#ifndef IMAGE_DISPLAY_H
#define IMAGE_DISPLAY_H
#include <wx/bitmap.h>
#include <wx/panel.h>
#include <wx/dcclient.h>
#include <wx/msgdlg.h>
#include <wx/dcmemory.h>
#include <wx/dcbuffer.h>
#include <vector>
#include <mutex>
#include <wx/timer.h>
#include <cstring>
#include <thread>
#include <atomic>
#include <condition_variable>
#include "ImageBitConver.h"
#include "MuliThreadSave.h"
#include "cameraDriver.h"
#include "WebMonitor.h"
#include "PixelFormat.h"

class ImageDisplay : public wxPanel
{
public:
	ImageDisplay(wxWindow* parent, wxWindowID winID,RemoteHandle* remoteHandle);
	virtual ~ImageDisplay();
	void showImage(const unsigned char* image, int width, int height,pixelFormat format);
	void showBitmap(const wxBitmap& sourceBit);
	void StaticDisplay(bool b);
	//标志函数正在被异步调用，不要马上退出线程
	static std::mutex mutAsyncing;
	//是否存活,如果对象析构了，就为false
	static std::atomic<bool> atomExists;

	//WebMonitor
	//这个函数会调用Dialog
	void SetRemoteParameter();
	void SetRemoteParameter(std::string IPAddress,std::string Port,std::string DeviceName);
	bool SetRemoterMirror(bool value);
private:
	void on_FileError(wxCommandEvent& event);
	Image8BitConver imageConver;
	void OnPaint(wxPaintEvent& e);
	wxTimer* refreshTimer;

	std::mutex mutInput;
	unsigned char* image;
	int width=10;
	int height=10;
  pixelFormat format=pixelFormat::MONO8;
	wxSize lastSize;  //记录上一帧的大小，如果发生变化要清除一下背景

	std::mutex mutOutput;
	wxMemoryDC memDC;
	wxBitmap bitmap;
	RemoteHandle* remotehandle;
	WebMonitor webMonitor;
	void on_WSclose_event(WSMonitorEvent& event);

	std::thread imageHandleThread;

	void onTimerOut(wxTimerEvent& timer);
	std::atomic<bool> threadRunFlag;
	std::atomic<bool> imageUploadFlag=false;

	friend void imageHandler(ImageDisplay* ptr);
};

enum class ImageDisplayID
{
	refreshTimer=150
};

#endif
